Dart int operator ==
Syntax & Examples


int.operator == operator

The `==` operator in Dart checks if this integer is equal to another value.


Syntax of int.operator ==

The syntax of int.operator == operator is:

operator ==(dynamic other) → bool

This operator == operator of int the equality operator.

Parameters

ParameterOptional/RequiredDescription
otherrequiredThe value to compare with.


✐ Examples

1 Comparison of 5 and 3

In this example,

  1. We assign the values 5 and 3 to the integer variables num1 and num2 respectively.
  2. We check if num1 is equal to num2.
  3. We print the result to standard output.

Dart Program

void main() {
  int num1 = 5;
  int num2 = 3;
  bool result = num1 == num2;
  print('Result of == operator: $result');
}

Output

Result of == operator: false

2 Comparison of 10 and 10

In this example,

  1. We assign the value 10 to both integer variables num1 and num2.
  2. We check if num1 is equal to num2.
  3. We print the result to standard output.

Dart Program

void main() {
  int num1 = 10;
  int num2 = 10;
  bool result = num1 == num2;
  print('Result of == operator: $result');
}

Output

Result of == operator: true

3 Comparison of -2 and -2

In this example,

  1. We assign the values -2 to both integer variables num1 and num2.
  2. We check if num1 is equal to num2.
  3. We print the result to standard output.

Dart Program

void main() {
  int num1 = -2;
  int num2 = -2;
  bool result = num1 == num2;
  print('Result of == operator: $result');
}

Output

Result of == operator: true

Summary

In this Dart tutorial, we learned about operator == operator of int: the syntax and few working examples with output and detailed explanation for each example.